import React , { Component , PropTypes } from 'react';

import {
    Route,
    Switch,
    Redirect
} from 'mirrorx';

export default class CustomRouter extends Component {
    constructor(){
        super();
    }

    static propTypes = {
        routers:PropTypes.array,
        className:()=>PropTypes.className
    }

    static defaultProps = {
        routers:[],
        className:""
    };

    render(){
        const { routers , className } = this.props;
        return(
            <div className={className}>
                <Switch>
                    {routers.map((route, i) => {
                        const exact = route.exact !== undefined  ? route.exact : true;
                        const enterFun = route.enter == undefined ? () => {} : route.enter ;
                        return (
                            <Route path={route.path} exact={exact} key={i} render={ props =>
                                React.cloneElement( route.component, {
                                    ...props ,
                                    routes:route.children || []
                                })
                            }/>
                        )
                    })}
                    {/*<Route component={()=> <Redirect to="/"/> } />*/}
                </Switch>
            </div>
        )

    }
};